package com.example.yls.myapplication;

import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button btn1;
    private Button btn2;
    private myBroadcastReceiver receiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //广播接受者的注册
        /*receiver=new myBroadcastReceiver();
        IntentFilter filter=new IntentFilter();
        filter.addAction("weather_info");
        filter.addAction("traffice_info");
        registerReceiver(receiver,filter);*/

        btn2=findViewById(R.id.btn_2);
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                intent.setAction("traffice_info");
                intent.putExtra("traffice","堵车");
                intent.putExtra("time","25");
                sendBroadcast(intent);

            }
        });


        btn1=findViewById(R.id.btn_1);
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent();
                intent.setAction("weather_info");
                intent.putExtra("weather","晴天");
                intent.putExtra("wendu","25");
                sendBroadcast(intent);
            }
        });
    }
    @Override
    protected void onDestroy() {
        unregisterReceiver(receiver);
        super.onDestroy();
    }
}
